package com.community.web.master.controller;


import com.community.common.result.Result;
import com.community.web.master.domain.dto.SpecialDto;
import com.community.web.master.domain.dto.SpecialGoodsDto;
import com.community.web.master.domain.dto.PageGoodsDto;
import com.community.web.master.domain.dto.PageSpecialDto;
import com.community.web.master.domain.vo.PageResult;
import com.community.web.master.domain.vo.SpecialGoodsVo;
import com.community.web.master.service.ISpecialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李晶
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/master/special")
@Slf4j
@Api(tags = "促销接口")
public class SpecialController {
    @Autowired
    private ISpecialService iSpecialService;
    @GetMapping("/pageQuery")
    @ApiOperation("促销分页查询")
    public Result<PageResult> pageQuery(PageSpecialDto specialDto){
        log.info("促销分页查询"+specialDto);
        PageResult result = iSpecialService.pageQuery(specialDto);
        return Result.success(result);
    }

    @GetMapping("/{id}")
    @ApiOperation("分页查询模块下所有商品")
    public Result<PageResult> pageQueryGoodsById(@PathVariable Integer id, PageGoodsDto pageGoodsDto){
        log.info("查询模块下所有商品"+id+" "+pageGoodsDto);
        PageResult result =iSpecialService.pageQueryGoodsById(id,pageGoodsDto);
        return Result.success(result);
    }

    @DeleteMapping("/deleteGoods")
    @ApiOperation("删除模块下的商品")
    public Result deleteSpecialGoods(@RequestBody SpecialGoodsDto specialGoodsDto){
        log.info("删除模块下的商品"+ specialGoodsDto);
        iSpecialService.deleteSpecialGoods(specialGoodsDto);
        return Result.success();
    }

    @PostMapping("/addGoods/{id}")
    @ApiOperation("批量增加模块下的商品")
    public Result addSpecialGoods(@RequestBody List<String> goodsNos,@PathVariable Integer id){
        log.info("增加模块下的商品"+goodsNos+" "+id);
        iSpecialService.addSpecialGoods(id,goodsNos);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改模块")
    public Result update(@RequestBody SpecialDto specialDto){
        log.info("修改模块信息"+specialDto);
        iSpecialService.updateSpecial(specialDto);
        return Result.success();
    }
    @PostMapping
    @ApiOperation("新增模块")
    public Result addSpecial(@RequestBody SpecialDto specialDto){
        log.info("新增模块信息"+specialDto);
        iSpecialService.addSpecial(specialDto);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除模块")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除模块"+id);
        iSpecialService.deleteSpecial(id);
        return Result.success();
    }

}
